//
//  TableConfig.swift
//  soapp
//
//  Created by zhu xietong on 2017/9/5.
//  Copyright © 2017年 CocoaPods. All rights reserved.
//

import Foundation
import Eelay
import JoLoading
import soapp


//TableVConfig 使用demo;CollectionVConfig；ASTableVConfig，ASCollectionVConfig 也大体一样

//项目中广泛用的是继承ListController

class DetailCtr: UIViewController,TableVConfig{
    let sections:TP.section = [
        [
            ["cellID":"TOP","hex":"#ddd"],
            ["cellID":"TOP","hex":"#aaa"],
            
            ["name":__names.creat_info(10),"img":__images.one_str],
        ],
        [
            ["name":__names.creat_info(10),"img":__images.one_str],
            ["name":__names.creat_info(10),"img":__images.one_str],
            ["cellID":"Page"],
        ]
    ]
    let selector:TP.selector = [
        "cellID<TOP,Page>":TOPCell.self,
        "<section0>":TOPCell.self,
        "<section1>":InfoCell.self,
    ]
    
    let tableView = UITableView(frame: .zero, style: .plain)
    override func viewDidLoad() {
        super.viewDidLoad()
        view.eelay = [
            [tableView,[ee.T.L.B.R]],
        ]
        config(tables: [tableView])
        tableView.buildDynamicHeight()
        top_style = __demoStyle()

        tableView.load(sections: sections, selector: selector)
    }
    
    func touch(cell: Any, actionID: String, model: NSMutableDictionary) {}
}

extension DetailCtr
{
    class TOPCell: JoTableCell {
        let imgV = UIImageView()
        override func addLayoutRules() {
            contentView.eelay = [
                [imgV,[ee.T.L.B,[10,10,-10]],"100",100],
            ]
        }
        override func mo_model_reload() {
            imgV.img_url = mo.model["img",""]
            imgV.backgroundColor = UIColor(shex: mo.model["hex",""])
        }
    }
    class InfoCell: JoTableCell {
        let titleL = UILabel()
        override func addLayoutRules() {
            contentView.eelay = [
                [titleL,[ee.T.L.B.R,[10,10,-10,-10]]],
            ]
            titleL.ui.bfont16.cl_444.line(0).center.background(hex: "#ddd")
        }
        
        override func mo_model_reload() {
            titleL.text = mo.model["title",""]
        }
    }

}
